package at.ac.univie.zsu.aguataplan.domain;

import javax.persistence.Column;
import javax.persistence.Entity;

/**
 * @author gerry
 * 
 */
@Entity
public class EventAttributeValueString extends EventAttributeValue {

	@Column(nullable = false, unique = true)
	private String attValue;

	// ----------------------------------------------------
	// CONSTRUCTOR
	// ----------------------------------------------------

	public EventAttributeValueString() {

	}

	// ----------------------------------------------------
	// COMPARABLE
	// ----------------------------------------------------

	@Override
	public int compareTo(EventAttributeValue o) {
		if (o instanceof EventAttributeValueString) {
			EventAttributeValueString e = (EventAttributeValueString) o;
			if (this.attValue.compareToIgnoreCase(e.attValue) < 0) {
				return -1;
			} else if (this.attValue.compareToIgnoreCase(e.attValue) > 0) {
				return 1;
			}

			return 0;
		}
		return -1;

	}

	// ----------------------------------------------------
	// METHODS
	// ----------------------------------------------------

	public String toStringRelation() {
		StringBuffer sb = new StringBuffer();
		for (EventAttribute ea : refEventAttribute) {
			sb.append(attValue + " -> " + ea.toString());
			sb.append("\n");
		}

		return sb.toString();
	}

	public String toString() {
		return this.attValue;
	}

	public String toStringExtended() {
		StringBuilder sb = new StringBuilder();
		sb.append("AttValue: ").append(getAttValue()).append(", ");
		sb.append("Id: ").append(getId()).append(", ");
		sb.append("RefEventAttribute: ")
				.append(getRefEventAttribute() == null ? "null" : getRefEventAttribute().size()).append(", ");
		sb.append("RefDetectedEvent: ").append(getRefDetectedEvent()).append(", ");
		sb.append("Version: ").append(getVersion());
		return sb.toString();
	}

	public String toStringExport() {
		return this.attValue;
	}

	// ----------------------------------------------------
	// GETTER & SETTER
	// ----------------------------------------------------

	public String getAttValue() {
		return attValue;
	}

	public void setAttValue(String attValue) {
		this.attValue = attValue;
	}

}